Skip to content

don't emit organize-imports code action when result is identical#3177

Merged
Techatrix merged 6 commits into
zigtools:masterfrom
akhilesharora:fix-organize-imports-noop-edits
May 17, 2026
Merged

don't emit organize-imports code action when result is identical#3177
Techatrix merged 6 commits into
zigtools:masterfrom
akhilesharora:fix-organize-imports-noop-edits

Conversation

@akhilesharora
Copy link
Copy Markdown
Contributor

@akhilesharora akhilesharora commented Apr 16, 2026

When imports are already organized, source.organizeImports still returned insert + delete edits whose net effect is no change. Clients apply them anyway, which dirties the buffer, adds to the undo stack, and flickers virtual text diagnostics. The reporter notes gopls returns no edits in this case.

This builds the organize edits, applies them to the source in memory, and skips emitting the code action when the result equals the original text. Happy to switch to a structural check instead if that's preferred. Went with apply and compare because it seemed simpler to reason about.

Added a test with three already organized shapes that asserts no source.organizeImports action is returned; it fails on master and passes here. Also ran the built binary against the exact source from the issue as a sanity check.

Fixes #2523

The source.organizeImports code action always emitted insert + delete
edits whose net effect was no change, causing editor undo-stack churn
and diagnostic flicker on already-organized files.

Apply the generated edits in-memory and suppress the action if the
resulting source matches the original.

Fixes zigtools#2523
Comment thread tests/lsp_features/code_actions.zig Outdated
Comment thread tests/lsp_features/code_actions.zig Outdated
@akhilesharora akhilesharora requested a review from Techatrix May 16, 2026 14:43
@Techatrix Techatrix merged commit ae3ab43 into zigtools:master May 17, 2026
6 checks passed
@akhilesharora akhilesharora deleted the fix-organize-imports-noop-edits branch May 17, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

source.organizeImports code action sends edits even when none are necessary

2 participants